var app = getApp();

Page({
    data: {
        is_show_share: !1,
        cards: [],
        cardsh: [],
        cardshh: [],
        display: !0,
        is_akey: !1,
        mail_name: "",
        img_root: "",
        cards_s:0,
        timestamp: new Date().getTime()
    },
    
    onLoad: function(a) {
      console.log(app.siteInfo);
        var t = this;
        app.util.footer(this);
        var e = a.mid;
        t.setData({
            mmid: e,
          img_root:app.siteInfo.img_root
        }), app.util.getUserInfo(function(a) {
            t.setData({
                userInfo: a
            }), app.util.request({
                url: "entry/wxapp/MailSetup",
                data: {
                    m: "bbyscm_card"
                },
                success: function(a) {
                    t.setData({
                        mailsetup: a.data.data,
                        ontrial: a.data.data.ontrial,
                        pay_coll: a.data.data.pay_coll,
                        mail_p: a.data.data.mail_p,
                        mail_pay: a.data.data.mail_pay
                    });
                }
            }), app.util.request({
                url: "entry/wxapp/Setup",
                data: {
                    m: "bbyscm_card"
                },
                success: function(a) {
                    t.setData({
                        setup: a.data.data,
                        _is_load: !1
                    });
                }
            });
        });
    },
    onReady: function() {},
    onShow: function() {
        this.onPullDownRef(1), this.setData({
            sysinfo: app.globalData.sysinfo,
            _is_load: !1
        });
    },
    onPullDownRef: function() {
        var t = this;
        app.util.request({
          // url: "entry/wxapp/GetCard",
          url: "https://xcxshop.175.lzyhss.com/app/index.php?i=34&c=entry&m=bbyscm_card&do=getcard",
            data: {
              m: "bbyscm_card",
              // pstadid: '3'
              pstadid: t.data.mmid
            },
          success: function (a) {
            console.log('pstadid', t.data.mmid);
            console.log('GetCard', a);
            t.setData({
              cards_s: a.data.length,
              cards: a.data
            });
            console.log(t.data.cards);
                // 0 == a.data.errno && (0 == a.data.data && wx.showModal({
                //     title: "你还没有创建名片，不能创建分会",
                //     content: "你还没有创建名片，不能创建分会",
                //     showCancel: !1,
                //     success: function() {
                //         wx.navigateTo({
                //             url: "/pages/card/edit/card-edit"
                //         });
                //     }
                // }), 0 == a.data.data.akey ? t.setData({
                //     my_info: a.data.data,
                //     my_cardid: a.data.data.id,
                //     my_name: a.data.data.cardname,
                //     my_openid: a.data.data.openid
                // }) : t.setData({
                //     is_akey: !0
                // }));
            }
        }), 0 < t.data.mmid && app.util.request({
            url: "entry/wxapp/GetMail",
            data: {
                m: "bbyscm_card",
                pstadid: t.data.mmid
            },
            success: function(a) {
              console.log('GetMail',a);
                0 == a.data.errno && (t.setData({
                    mails: a.data.data,
                    aadid: a.data.data.id,
                    mail_name: a.data.data.mail_name,
                    admin_openid: a.data.data.admin_openid,
                    day: Math.floor(a.data.data.syts / 86400),
                    hour: Math.floor((a.data.data.syts - 24 * Math.floor(a.data.data.syts / 86400) * 3600) / 3600),
                    is_show: !1
                }), t.setData({
                    mails: a.data.data,
                    display: !1
                }), wx.setNavigationBarTitle({
                    title: a.data.data.mail_name
                }));
            }
        })
        // , app.util.request({
        //     url: "entry/wxapp/GetMyMailCard",
        //     data: {
        //         m: "bbyscm_card",
        //         mm_key: t.data.mmid
        //     },
        //     success: function(a) {
        //         0 == a.data.errno && t.setData({
        //             cards: a.data.data,
        //             cards_s: a.data.data.length,
        //             card_openid: a.data.data.openid
        //         });
        //     }
        // }), app.util.request({
        //     url: "entry/wxapp/GetMyMailCardh",
        //     data: {
        //         m: "bbyscm_card",
        //         mm_keyh: t.data.mmid
        //     },
        //   success: function (a) {
        //     console.log('GetMyMailCardh', a);
        //         0 == a.data.errno && t.setData({
        //             cardsh: a.data.data
        //         });
        //     }
        // }), app.util.request({
        //     url: "entry/wxapp/GetMyMailCardhh",
        //     data: {
        //         m: "bbyscm_card",
        //         mm_keyh: t.data.mmid
        //     },
        //   success: function (a) {
        //     console.log('GetMyMailCardhh', a);
        //         0 == a.data.errno && t.setData({
        //             cardshh: a.data.data
        //         });
        //     }
        // });
    },
    to_mails: function(a) {
        var t = this;
        JSON.stringify(a.detail.value);
        var e = a.detail.formId, i = t.data.mmid, s = t.data.mail_name, d = t.data.my_name, o = t.data.admin_openid, n = a.currentTarget.id;
        app.util.request({
            url: "entry/wxapp/PostMyMailssTo",
            data: {
                m: "bbyscm_card",
                form_id: e,
                mails_id: i,
                admin_openid: o,
                mail_member: n,
                mail_name: s,
                my_name: d,
                mail_key: 1,
                page: "pages/card/mail/mail?mid=" + i
            }
        }), this.setData({
            is_load_more: !0,
            cards: [],
            cardsh: [],
            cardshh: []
        }), this.onPullDownRef(1);
    },
    toh_mails: function(a) {
        JSON.stringify(a.detail.value);
        var t = this.data.mmid, e = this.data.admin_openid, i = a.currentTarget.id;
        app.util.request({
            url: "entry/wxapp/PostMyMailssTo",
            data: {
                m: "bbyscm_card",
                mails_id: t,
                admin_openid: e,
                mail_member: i,
                mail_key: 2
            }
        }), this.setData({
            is_load_more: !0,
            cards: [],
            cardsh: [],
            cardshh: []
        }), this.onPullDownRef(1);
    },
    call_phone_bind: function(a) {
        var t = a.currentTarget.id;
        "" != t && wx.makePhoneCall({
            phoneNumber: t
        });
    },
    onShareAppMessage: function() {
        var a = this;
        return {
            title: "你好！" + a.data.my_name + "邀请您加入 \n 【" + a.data.mail_name + "】",
            desc: "你好！" + a.data.my_name + "邀请您加入 \n 【" + a.data.mail_name + "】",
            path: "pages/card/mail_join/mail_join?cid=" + a.data.mmid,
            img: a.data.imgs,
            imgs: [],
            success: function(a) {
                wx.showToast({
                    title: "转发成功",
                    icon: "success",
                    duration: 1e3,
                    mask: !0
                });
            },
            fail: function(a) {
                wx.showToast({
                    title: "转发失败",
                    icon: "error",
                    duration: 1e3,
                    mask: !0
                });
            }
        };
    },
    mailpayopen: function(a) {
        console.log("成功", a);
        var t = this;
        0 < t.data.mailsetup.pay_coll - t.data.my_info.money ? this.setData({
            pay_coll: t.data.mailsetup.pay_coll,
            bupay_coll: (t.data.mailsetup.pay_coll - t.data.my_info.money).toFixed(2),
            pay_term: "postmailpay",
            pmailid: a.currentTarget.id,
            pform_id: a.detail.formId,
            payopen: !0
        }) : this.setData({
            pay_coll: t.data.mailsetup.pay_coll,
            bupay_coll: (0).toFixed(2),
            pay_term: "postmailpay",
            pmailid: a.currentTarget.id,
            pform_id: a.detail.formId,
            payopen: !0
        });
    },
    checkboxChange: function(a) {
        console.log("当checkbox-group中的checkbox选中或者取消是我被调用"), console.log(a.detail);
        var t = this;
        a.detail.value[0] ? 0 < t.data.pay_coll - a.detail.value[0] ? t.setData({
            bupay_coll: (t.data.pay_coll - a.detail.value[0]).toFixed(2)
        }) : t.setData({
            bupay_coll: (0).toFixed(2)
        }) : t.setData({
            bupay_coll: t.data.pay_coll
        });
    },
    paycloes: function(a) {
        this.setData({
            payopen: !1
        });
    },
    postmailpay: function(a) {
        console.log("续费", a);
        var t = this;
        t.setData({
            btn_disabled: !0,
            submitIsLoading: !0,
            payopen: !1
        }), JSON.stringify(a.detail.value);
        var e = t.data.pformId, i = t.data.my_cardid, s = t.data.pmailid, d = t.data.bupay_coll, o = t.data.pay_coll - d;
        if (!s) return wx.showModal({
            title: "提示",
            content: "获取信息失败",
            showCancel: !1,
            success: function(a) {
                a.confirm, t.setData({
                    btn_disabled: !1,
                    submitIsLoading: !1
                });
            }
        }), !1;
        0 < d ? (t.setData({
            pay: !0
        }), app.util.request({
            url: "entry/wxapp/Pay",
            data: {
                m: "bbyscm_card",
                cost: d,
                id: s
            },
            success: function(a) {
                wx.requestPayment({
                    timeStamp: a.data.timeStamp,
                    nonceStr: a.data.nonceStr,
                    package: a.data.package,
                    signType: a.data.signType,
                    paySign: a.data.paySign,
                    success: function(a) {
                        t.setData({
                            Msg: a.errMsg,
                            pay: !1
                        }), wx.showToast({
                            title: "提交中...",
                            icon: "loading",
                            duration: 1e4
                        }), app.util.request({
                            url: "entry/wxapp/PostWordspay",
                            data: {
                                m: "bbyscm_card",
                                cardid: i,
                                wordsid: s,
                                pay_class: 2,
                                days: 365,
                                coll: d,
                                yepay_coll: o
                            },
                            method: "POST"
                        }), app.util.request({
                            url: "entry/wxapp/PostMailpays",
                            data: {
                                m: "bbyscm_card",
                                mailid: s,
                                days: 365,
                                cardid: i,
                                yepay_coll: o
                            },
                            method: "POST",
                            success: function(a) {
                                0 == a.data.errno ? (app.util.request({
                                    url: "entry/wxapp/message1",
                                    data: {
                                        m: "bbyscm_card",
                                        form_id: e,
                                        pay_class: 2,
                                        pay_classid: s,
                                        coll: d,
                                        days: 365,
                                        cardname: t.data.my_info.cardname,
                                        page: "pages/card/mail/mail?mid=" + s
                                    },
                                    success: function(a) {
                                        wx.reLaunch({
                                            url: ""
                                        });
                                    }
                                }), wx.showModal({
                                    title: "提示",
                                    content: "提交成功",
                                    showCancel: !1,
                                    success: function(a) {}
                                })) : wx.showModal({
                                    title: "提示",
                                    content: a.data.message,
                                    showCancel: !1,
                                    success: function(a) {
                                        a.confirm;
                                    }
                                }), this.onPullDownRef(1);
                            },
                            fail: function(a) {
                                wx.showModal({
                                    title: "提示",
                                    content: a.data.message,
                                    showCancel: !1,
                                    success: function(a) {
                                        a.confirm;
                                    }
                                });
                            },
                            complete: function() {
                                wx.hideToast();
                            }
                        });
                    },
                    fail: function(a) {
                        t.setData({
                            pay: !1,
                            btn_disabled: !1,
                            submitIsLoading: !1
                        }), wx.showToast({
                            title: "支付失败",
                            duration: 1e3
                        });
                    }
                });
            }
        })) : (app.util.request({
            url: "entry/wxapp/PostWordspay",
            data: {
                m: "bbyscm_card",
                cardid: i,
                wordsid: s,
                pay_class: 2,
                days: 365,
                coll: d,
                yepay_coll: o
            },
            method: "POST"
        }), app.util.request({
            url: "entry/wxapp/PostMailpays",
            data: {
                m: "bbyscm_card",
                mailid: s,
                days: 365,
                cardid: i,
                yepay_coll: o
            },
            method: "POST",
            success: function(a) {
                console.log("4", a), 0 == a.data.errno && wx.showModal({
                    title: "提示",
                    content: "提交成功",
                    showCancel: !1,
                    success: function(a) {
                        t.setData({
                            btn_disabled: !1,
                            submitIsLoading: !1
                        });
                    }
                });
            }
        }), this.onPullDownRef(1));
    },
    onPullDownRefresh: function() {
        setTimeout(function() {
            wx.stopPullDownRefresh();
        }, 1e3);
    },
    onCreateImgTap: function() {
        var e = !1;
        app.util.request({
            url: "entry/wxapp/CreateImage",
            data: {
                m: "bbyscm_card"
            },
            method: "POST",
            success: function(a) {
                if (0 == a.data.errno) {
                    var t = a.data.data;
                    wx.previewImage({
                        urls: [ t ]
                    }), e = !0, wx.hideToast();
                }
            }
        }), setTimeout(function() {
            e || wx.showToast({
                title: "请稍后...",
                icon: "loading",
                duration: 1e4
            });
        }, 11e3);
    },
    nav_home: function() {
        wx.switchTab({
            url: "/pages/card/index/index"
        });
    },
    nav_back: function() {
        wx.switchTab({
            url: "/pages/card/mails/mail_list"
        });
    },
    mail_admin: function(a) {
        wx.switchTab({
            url: "../mailad/mailad?amid" + that.data.mmid
        });
    },
    look_card_info_bind: function(a) {
        wx.navigateTo({
            url: "../info/info?card_id=" + a.currentTarget.id
        });
    },
    show_share_bind: function() {
        var a = this;
        a.setData({
            is_show_share: !0
        }), setTimeout(function() {
            a.hide_share_bind();
        }, 2e3);
    },
    hide_share_bind: function() {
        this.setData({
            is_show_share: !1
        });
    },
    getcodes: function(a) {
        var i = !1, t = a.target.dataset.id;
        app.util.request({
            url: "entry/wxapp/GetCodeM",
            data: {
                m: "bbyscm_card",
                cardid: t,
                path: "pages/card/mail_join/mail_join?cid=" + this.data.mmid
            },
            method: "POST",
            success: function(a) {
                if (0 == a.data.errno) {
                    var t = a.data.data;
                    wx.previewImage({
                        urls: [ t ]
                    }), setTimeout(function() {
                        i = !0, wx.hideToast();
                    }, 2e3);
                    var e = a.data.data;
                    wx.downloadFile({
                        url: e,
                        success: function(a) {
                            wx.saveImageToPhotosAlbum({
                                filePath: a.tempFilePath,
                                success: function(a) {},
                                fail: function(a) {
                                    "saveImageToPhotosAlbum:fail auth deny" === a.errMsg && wx.openSetting({
                                        success: function(a) {
                                            a.authSetting["scope.writePhotosAlbum"];
                                        }
                                    });
                                }
                            });
                        }
                    }), i = !0, wx.hideToast();
                }
            }
        }), setTimeout(function() {
            i || wx.showToast({
                title: "请稍后...",
                icon: "loading",
                duration: 1e4
            });
        }, 11e3);
    }
});